import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:file_picker_example/src/file_picker_demo.dart';
import 'package:flutter/widgets.dart';
import 'package:file_picker_copy/image_picker.dart';
import 'package:file_picker_copy/file_picker.dart';

//void main() => runApp(MyApp());
void main() => runApp(MyPage());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Image Picker Demo',
      home: MyHomePage(title: 'Image Picker Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, this.title}) : super(key: key);

  final String? title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final ImagePicker _picker = ImagePicker();


  String? filePath;


  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title!),
        ),
        body: Center(
          child: Container(
            child: Semantics(
              label: 'image_picker_example_from_gallery',
              child: Column(
                children: [
                  Container(height: 20,),
                  FloatingActionButton(
                    onPressed: () async {
                      final pickedFile = await _picker.pickImage(source: ImageSource.camera, );
                      print("filePath====>${pickedFile?.path??""}");

                      filePath = pickedFile?.path;

                      setState(() { });
                    },
                    heroTag: 'image0',
                    tooltip: 'Pick Image from gallery',
                    child: const Icon(Icons.photo),
                  ),
                  Container(height: 20,),
                  FloatingActionButton(
                    onPressed: () async {
                      final pickedFile = await _picker.pickMultiImage();
                      // _onImageButtonPressed(ImageSource.gallery, context: context);

                      filePath = pickedFile?.first.path;

                      setState(() { });
                    },
                    heroTag: 'image0',
                    tooltip: 'Pick Image from camera',
                    child: const Icon(Icons.camera),
                  ),
                  Container(height: 20,),
                  FloatingActionButton(
                    onPressed: () async {
                      final pickedFile = await FilePicker.platform.pickFiles(
                        type: FileType.any,
                        allowMultiple: true,
                      );

                      filePath = pickedFile?.files.first.path;

                      setState(() { });
                    },
                    heroTag: 'image0',
                    tooltip: 'Pick Image from camera',
                    child: const Icon(Icons.upload_file),
                  ),
                  Container(height: 20,),
                  FloatingActionButton(
                    onPressed: () async {
                      final files = await _picker.customPickMultiImage();
                      print("files====>${files?.first.path}");
                    },
                    heroTag: 'image0',
                    tooltip: 'Pick Image from gallery',
                    child: const Icon(Icons.photo),
                  ),
                  Container(
                    width: 200,
                    height: 200,
                    color: Colors.yellow,
                    child: filePath==null?Container():Image.file(File(filePath!)),
                  ),
                ],
              ),
            ),
          ),
        )
    );
  }


}

